package Model;

import java.io.*;
import java.util.*;

public class contactList {
	public ArrayList list;
	
	public contactList() {
		list = new ArrayList<Contact>();
		
	}
	
	public ArrayList load() {
		
		FileInputStream file;
		try {
			file = new FileInputStream("contacts.csv");
			BufferedReader br = new BufferedReader(new InputStreamReader(new DataInputStream(file)));
			String read = new String();
			read = br.readLine(); //Skip first line
			
			while ((read = br.readLine()) != null)
			{
				StringTokenizer str = new StringTokenizer(read, ";"); 
				Contact contactAdd = new Contact();
				contactAdd.firstName = str.nextToken();
				contactAdd.lastName = str.nextToken();
				contactAdd.homeAddress = str.nextToken();
				contactAdd.companyAddress = str.nextToken();
				contactAdd.personalMobilePhone = str.nextToken();
				contactAdd.personalHomePhone = str.nextToken();
				contactAdd.proMobilePhone = str.nextToken();
				contactAdd.proOfficePhone = str.nextToken();
				contactAdd.homePage = str.nextToken();
				contactAdd.proEmail = str.nextToken();
				contactAdd.personalEmail = str.nextToken();
				contactAdd.otherIM = str.nextToken();
				contactAdd.otherSkype = str.nextToken();
				contactAdd.dateAdded = str.nextToken();
				contactAdd.group = str.nextToken();
				contactAdd.picturePath = str.nextToken();
				list.add(contactAdd);
			}
			System.out.println("loaded");
			br.close();
			file.close();
			return list;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
	
}
